﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SonCa.SocialNetwork.Web.ASCX.IPresenters;
using SonCa.SocialNetwork.Web.ASCX.Presenters;
using Core.DataAccess;
using SonCa.SocialNetwork.Web.HelperClass;

namespace SonCa.SocialNetwork.Web.ASCX
{
    public partial class DisplayAllProfile : System.Web.UI.UserControl, IAllProfileDisplay
    {
        private AllProfileDisplayPresenter _presenter;
        private static List<FriendsInvitation> lstFriendInvitationID = new List<FriendsInvitation>();
        private static List<Friend> lstFriends = new List<Friend>();

        protected void Page_Load(object sender, EventArgs e)
        {
            _presenter = new AllProfileDisplayPresenter();
            _presenter.Init(this);
        }

        public void GetInfo()
        {
            _presenter = new AllProfileDisplayPresenter();
            _presenter.Init(this);
            lstFriendInvitationID = _presenter.GetListFriendsRequestByAccountID();
            lstFriends = _presenter.GetListFriendsByAccountID();
        }

        public void LoadAllDisplay(FriendRequestHelper contentObj)
        {
            // filter friend
            foreach (Friend fr in lstFriends)
            {
                if (contentObj.AccountID == fr.AccountID)
                {
                    imgAddFriend.Style.Add("display", "none");
                    return;
                }
            }

            linkOtherFriend.Attributes.Add("href","../Personals/PersonalPage.aspx?otherAccountID=" + contentObj.AccountID);
            imgFriend.ImageUrl = "~/Images/ProfileAvatar/ProfileImage.aspx?AccountID=" + contentObj.AccountID.ToString();
            lblNameFriend.Text = contentObj.FullName;
            imgAddFriend.Attributes.Add("class", contentObj.AccountID.ToString());
            loading_addfriend.Attributes.Add("class","loading_addfriend_" + contentObj.AccountID.ToString());

            if (lstFriendInvitationID != null)
            {
                foreach (FriendsInvitation fr in lstFriendInvitationID)
                {
                    if (contentObj.AccountID == fr.BecameAccountID)
                    {
                        imgAddFriend.Src = "../img/requestsended.png";
                        imgAddFriend.Attributes.Remove("onclick");
                        imgAddFriend.Attributes.Remove("style");
                    }
                }
            }
        }
    }
}